﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace StarBotDotNet
{
    public static class Utilities
    {
        private static Object WriteLineLock = new Object();
        private static StreamWriter logfile = null;
        private static string logfileLocation = null;
        public static bool EnabledLogs = true;
        public static bool ConsolePrintEnbled = true;

        public static void WriteColorLine(ConsoleColor color, string format, params object[] arg)
        {
            lock (WriteLineLock)
            {
                if (EnabledLogs)
                {
                    if (logfileLocation == null || logfile == null)
                    {
                        logfileLocation = System.Configuration.ConfigurationSettings.AppSettings["logFilePath"].ToString();

                        if (!File.Exists(logfileLocation))
                        {
                            logfile = new StreamWriter(logfileLocation);
                        }
                        else
                        {
                            logfile = File.AppendText(logfileLocation);
                        }
                    }

                    if (logfile != null)
                    {
                        logfile.WriteLine(format, arg);
                        logfile.Flush();
                    }
                }

                if (ConsolePrintEnbled)
                {
                    Console.ForegroundColor = color;
                    Console.WriteLine(format, arg);
                    Console.ResetColor();
                }
            }
        }
    }
}
